<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Driver extends Model
{
    use Notifiable;
    protected $fillable = ['name','phone','car_no','car_type','num','free','line_id','return_trip'];

    public function line() {
        return $this->belongsTo(Line::class);
    }

    public function getStatusTextAttribute() {
        return $this->openid?'已绑定':'未绑定';
    }

    public function getTripTextAttribute() {
        $line = $this->line;
        if($this->return_trip == 1) {
            return $line->end.'&nbsp;-&nbsp;'.$line->start;
        } else {
            return $line->start.'&nbsp;-&nbsp;'.$line->end;
        }
    }

    public function getReturnTripTitleAttribute() {
        return ($this->return_trip == 1)?'(返程)':'';
    }
}
